<template>
  <div class="YouMengLink">
    <button id="btn" style="display: none">test</button>
  </div>
</template>

<script>
export default {
  mounted() {
    let channel = this.$route.query.channel ? this.$route.query.channel : "";
    const script = document.createElement("script");

    script.type = "text/javascript";

    script.src = "https://g.alicdn.com/jssdk/u-link/index.min.js";

    document.getElementsByTagName("head")[0].appendChild(script);
    script.onload = function () {
      //友盟Ulink
      window.ULink([
        {
          id: "usr14f5aobb3bh0v",
          data: {
            channel: channel,
          },
          selector: "#btn",
          // auto: true,
          timeout: 2000,
          lazy: false,
          auto: true,
          useOpenInBrowerTips: "default",
          // function (ctx) {
          //   //提示浏览器打开 带遮罩层demo
          //   return `<div style="position:fixed;left:0;top:0;background:rgba(255,0,255,0.5);width:100%;height:100%;z-index:19910324;"></div>`;
          // },
          proxyOpenDownload: function (defaultAction, LinkInstance) {
            console.log(defaultAction);
            if (LinkInstance.solution.type === "scheme") {
              // qq或者微信环境特殊处理下
              if (ULink.isWechat || ULink.isQQ) {
                // 在qq或者微信环境执行内置逻辑，具体内置逻辑为:当设置了useOpenInBrowerTips字段时，qq&&微信&&scheme时，启用蒙层提示去浏览器打开
                defaultAction();
                //   window.location.href = LinkInstance.solution.downloadUrl;
              } else {
                window.location.href = LinkInstance.solution.downloadUrl;
              }
            } else if (LinkInstance.solution.type === "universalLink") {
            }
          },
        },
      ]);
    };
  },
};
</script>

<style lang="less" scoped>
</style>